package com.gomefinance.consumer;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;

/**
 * @author zhangfuqiang3@gome.com.cn
 * @version 1.0
 * @date 2024/12/28
 * @description:
 **/
@Service
public class KafkaConsumerService {
    private static final Logger logger = LoggerFactory.getLogger(KafkaConsumerService.class);
    @KafkaListener(topics = "${kafka.consumer.topic}", groupId = "${kafka.consumer.group-id}")
    public void listen(String key, String message) {
        try {
            // 处理消息
            //logger.info("接收到消息 - 主题: {}, 键: {}, 内容: {}", "zfq-test-topic", key, message);
            // 添加业务逻辑
        } catch (Exception e) {
            logger.error("处理消息失败：{}", e.getMessage());
            // 可以抛出异常以触发重试机制或发送到死信队列
            throw e;
        }
    }
}
